package aircraftWar;

import java.awt.image.BufferedImage;

/**
 * 说明：英雄机
 *
 * @author: PYS
 * @date: 2022/11/8
 **/
public class Hero extends FlyingObject {
    private int life;
    private int fire;

    public Hero() {
        super(97, 139, 140, 550);
        life = 3;
        fire = 0;
    }

    public void step() {
    }

    public void moveTo(int x , int y) {
        this.x = x - this.width / 2;
        this.y = y - this.height / 2;
    }

    int index = 0;
    /** 重写getImage()获取图片 */
    public BufferedImage getImage() {
        return Images.heros[index++%Images.heros.length];
        /* 执行过程:
                              index=0
           10M  返回heros[0]  index=1
           20M  返回heros[1]  index=2
           30M  返回heros[0]  index=3
           40M  返回heros[1]  index=4
           50M  返回heros[0]  index=5
         */
    }

    public Bullet[] shoot() {
        int xStep = this.width/4;
        int yStep = 5;
        if (fire > 0) {  //双倍
            Bullet[] bs = new Bullet[2];
            bs[0] = new Bullet(this.x+xStep-5, this.y-yStep);
            bs[1] = new Bullet(this.x+3*xStep-5, this.y-yStep);
            fire -= 2;
            return bs;
        } else {
            Bullet[] bs = new Bullet[1];
            bs[0] = new Bullet(this.x+2*xStep-5, this.y-yStep);
            return bs;
        }
    }

    public void addLife() {
        this.life++;
    }

    public void addFire() {
        this.fire += 40;
    }

    public int getLife() {
        return this.life;
    }

    public int getFire() {
        return this.fire;
    }

    public void clearFire() {
        this.fire = 0;
    }

    public void subtractLife() {
        this.life--;
    }
}
